package cxf.spring.demo.gui;

import cxf.spring.demo.gui.model.MessageStorageModel;
import cxf.spring.demo.service.UserService;
import cxf.spring.demo.service.MessageService;
import cxf.spring.demo.storage.ClientStorage;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * User: Vlad Vinichenko (akerigan@gmail.com)
 * Date: 07.03.2009
 * Time: 16:08:20
 */
public class MessagesFrame extends JFrame {

    private static Log log = LogFactory.getLog(MessagesFrame.class);
    private UserService userService;
    private MessageService messageService;
    private ClientStorage clientStorage;

    public MessagesFrame() {
        super();
        initModel();
        initGui();
    }

    private void initModel() {
        ApplicationContext context = new ClassPathXmlApplicationContext("/applicationContext.xml");
        userService = (UserService) context.getBean("userService");
        messageService = (MessageService) context.getBean("messageService");
        clientStorage = (ClientStorage) context.getBean("storage");
    }

    private void initGui() {
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

        JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

        MessageStorageModel model = new MessageStorageModel();
        JTable table = new JTable(model);

        splitPane.add(table);

        setSize(400, 300);
        setVisible(true);
    }
}
